// pages/task/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    taskList: [
      {
        name: "1.新生儿喂养",
        isFinished: true
      },
      {
        name: "2.护理",
        isFinished: true
      },
      {
        name: "3.观察",
        isFinished: true
      },
      {
        name: "4.给婴儿洗澡",
        isFinished: false
      },
      {
        name: "5.洗尿布",
        isFinished: false
      },
      {
        name: "6.洗婴儿衣服",
        isFinished: false
      },
      {
        name: "7.拆洗婴儿被褥及新生儿护理",
        isFinished: false
      },
      {
        name: "8.育儿常识及婴儿用品的消毒等",
        isFinished: false
      },
      {
        name: "9.育儿预防接种",
        isFinished: false
      },
      {
        name: "10.新生儿的按摩、保健",
        isFinished: false
      },
      {
        name: "11.与婴儿对话",
        isFinished: false
      },
      {
        name: "12.益智健身操",
        isFinished: false
      },
      {
        name: "13.游泳",
        isFinished: false
      },
      {
        name: "14.晒太阳以及认知能力的培训 等科学育儿",
        isFinished: false
      }
    ]

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  onClickFinishTaskAction: function (ev) {
    let index = ev.currentTarget.dataset.index
    if(index > 0) {
      const item = this.data.taskList[index-1]
      if(!item.isFinished) {
        wx.showToast({
          title: '请先完成前面的任务',
        })
        return;
      }
    } 
    this.data.taskList[index].isFinished = true;
    this.setData({ taskList: this.data.taskList });
  },
})